package com.ymatou.iapi.trading.userquery.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.userquery.parameter.GetOrderedReq;
import com.ymatou.iapi.trading.userquery.service.GetOrderedCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.YMTDateUtil;

/**
 * 查询用户在指定时间是否下单
 */
@TestSuite
public class Ts_GetOrdered {
	private static GetOrderedReq getOrderedReq;
	private static GetOrderedCall getOrderedCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取订单资金信息");
	}

	@Before
	public void caseUp() {
		getOrderedReq = new GetOrderedReq();

		getOrderedCall = new GetOrderedCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getOrderedCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrdered_001() {
		Logger.start(true, "获取用户指定时间是下过单");
		try {
			long userId = Long.valueOf(EnvSetup.getData("BuyUserId"));
			getOrderedReq.setUserId(userId);

			getOrderedReq.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-1,
					YMTDateUtil.YMDTHMS_STRING));

			getOrderedReq.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,
					YMTDateUtil.YMDTHMS_STRING));

			getOrderedCall.setData(getOrderedReq);

			getOrderedCall.callService();

			Logger.verifyEquals("200", getOrderedCall.getCode(), "验证code");

			Logger.verifyEquals(true, getOrderedCall.getData().getBoolean("ordered"), "验证ordered");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrdered_002() {
		Logger.start(true, "获取用户指定时间没有下过单");
		try {
			int userId = new OrderCallService().createNewUser();
			getOrderedReq.setUserId(userId);

			getOrderedReq.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-1,
					YMTDateUtil.YMDTHMS_STRING));

			getOrderedReq.setEndTime(YMTDateUtil.getBeforeOrNextDay(2,
					YMTDateUtil.YMDTHMS_STRING));

			getOrderedCall.setData(getOrderedReq);

			getOrderedCall.callService();

			Logger.verifyEquals("200", getOrderedCall.getCode(), "验证code");

			Logger.verifyEquals(false, getOrderedCall.getData().getBoolean("ordered"), "验证ordered");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrdered_003() {
		Logger.start(true, "用户id为null");
		try {
			getOrderedReq.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-1,
					YMTDateUtil.YMDTHMS_STRING));

			getOrderedReq.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING));

			getOrderedCall.setData(getOrderedReq);

			getOrderedCall.callService();

			Logger.verifyEquals("400", getOrderedCall.getCode(), "验证code");

			Logger.verifyEquals("100", getOrderedCall.getBCode(), "验证bcode");

			Logger.verifyEquals("userId:买家Id不能为0", getOrderedCall.getMsg(),
					"验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrdered_004() {
		Logger.start(true, "开始时间为null");
		try {
			
			long userId = Long.valueOf(EnvSetup.getData("BuyUserId"));
			getOrderedReq.setUserId(userId);

			getOrderedReq.setEndTime(YMTDateUtil.getBeforeOrNextDay(1,
					YMTDateUtil.YMDTHMS_STRING));

			getOrderedCall.setData(getOrderedReq);

			getOrderedCall.callService();

			Logger.verifyEquals("400", getOrderedCall.getCode(), "验证code");

			Logger.verifyEquals("100", getOrderedCall.getBCode(), "验证bcode");

			Logger.verifyEquals("beginTime:查询开始时间不能为null",
					getOrderedCall.getMsg(), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrdered_005() {
		Logger.start(true, "结束时间为null");
		try {
			long userId = Long.valueOf(EnvSetup.getData("BuyUserId"));
			getOrderedReq.setUserId(userId);

			getOrderedReq.setBeginTime(YMTDateUtil.getBeforeOrNextDay(-1,
					YMTDateUtil.YMDTHMS_STRING));

			getOrderedCall.setData(getOrderedReq);

			getOrderedCall.callService();

			Logger.verifyEquals("400", getOrderedCall.getCode(), "验证code");

			Logger.verifyEquals("100", getOrderedCall.getBCode(), "验证bcode");

			Logger.verifyEquals("endTime:查询截止时间不能为null",
					getOrderedCall.getMsg(), "验证msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}